
/*
 XMail OSAX -- Copyright (C) 2004, 2005, 2006, 2007 Jean-Baptiste LE STANG osax@lestang.org
 
	
 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or
 (at your option) any later version.
 
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 */
#include <Security/Security.h>
#include "AEDescUtils.h"
#include "Terminology.h"
#include "mail.h"
#include "smtp.h"

#define kXMailMaxPathLength 4096

int XMailGetTypeRecipientsCount(const AppleEvent * theEvent,AEKeyword type);
int XMailGetRecipientsCount(const AppleEvent * theEvent);
char *   XMailEncodeEmailAddress(char * rawemail,char ** name, char ** email);
XMailEncoder * XMailGetEncoder();
void XMailSetEncoder(XMailEncoder * encoder);

OSStatus XMailFindPasswordInKeychain(char * keychainName, char * smtp, char * username, int port, char ** password);
OSStatus XMailConvertText(char * inputText,char ** outputText, char * inputEncodingName, char * outputEncodingName);
OSStatus XMailMakeErrorReply(AppleEvent *theReply, const OSErr theErrorCode, char *theMessage);
OSStatus XMailGetDescString(const AEDesc *theDesc, char **  theString);
OSStatus XMailGetTextParamAsString(const AppleEvent *theEvent, const AEKeyword theKeyword, char ** theField);
OSStatus XMailGetUnicodeParamAsString(const AppleEvent *theEvent, const AEKeyword theKeyword, const TextEncoding toEncoding, char ** theField);
OSStatus XMailGetListItemAsString(const AEDescList *theList, const DescType theType, const SInt32 theIndex, char ** theField);
OSStatus XMailGetParamListItemAsString(const AppleEvent *theEvent, const AEKeyword theKeyword, const DescType theType, const SInt32 theIndex,char *theField);
OSStatus XMailGenericEmail(const AppleEvent * theEvent, const AEKeyword theKeyword, char ** dest,char **destEsc);
OSStatus XMailDoReplyTo(const AppleEvent * theEvent, mail_t * mail);
OSStatus XMailDoErrorsTo(const AppleEvent * theEvent, mail_t * mail);
OSStatus XMailDoFrom(const AppleEvent * theEvent, mail_t * mail);
OSStatus XMailDoLogin(const AppleEvent * theEvent, mail_t * mail);
OSStatus XMailDoPassword(const AppleEvent * theEvent, mail_t * mail);
OSStatus XMailDoRawBody(const AppleEvent * theEvent, mail_t * mail, char * inputEncoding);
OSStatus XMailDoDate(const AppleEvent * theEvent, mail_t * mail);
OSStatus XMailDoBody(const AppleEvent * theEvent, mail_t * mail,char * inputEncoding,char * outputEncoding);
OSStatus XMailDoSubject(const AppleEvent * theEvent, mail_t * mail,char * inputEncoding);
OSStatus XMailDoServer(const AppleEvent * theEvent, mail_t * mail);
OSStatus XMailDoRecipients(const AppleEvent *theEvent, const AEKeyword theKeyword, mail_t * mail,recipient_t theRecipientKind);
OSStatus XMailDoAttachments(const AppleEvent *theEvent,mail_t * mail);
OSStatus XMailDoGetPort(const AppleEvent * theEvent,  mail_t * mail);
OSStatus XMailDoGetTimeout(const AppleEvent * theEvent,  mail_t * mail);
OSStatus XMailDoPriority(const AppleEvent *theEvent,mail_t * mail);
OSStatus XMailDoGetSSL(const AppleEvent * theEvent,mail_t * mail);
OSStatus XMailDoGetSSLCertificates(const AppleEvent * theEvent,mail_t * mail);
OSStatus XMailDoGetSASL(const AppleEvent * theEvent,mail_t * mail);
OSStatus XMailDoExtraHeaders(const AppleEvent *theEvent,mail_t * mail);
OSStatus XMailGetEncoding(const AppleEvent * theEvent,AEKeyword key, char ** encodingName);
OSStatus XMailGenerateKeyWordRcptsList(const AppleEvent * theEvent,AEKeyword key, mail_t * mail);
OSStatus XMailGenerateRcptsList(const AppleEvent * theEvent, mail_t * mail);